home *** CD-ROM | disk | FTP | other *** search
- //
- // MFC_PGM is intended as a simple example of the use of
- // the Microsoft Foundation Class (MFC) library with the
- // FTP Client Engine for C/C++ (FCE4C).
- //
- // This example logs onto our FTP site and downloads the
- // file PRODUCTS.TXT.
- //
- // Edit PASSWORD with your email address (see line 112 below)
- // before compiling.
- //
-
- #include "stdafx.h"
- #include "resource.h"
-
- #include "fce.h"
- #include "mfc_pgm.h"
-
- static CWnd * MainWndPtr;
-
- // CMainWindow: constructor
-
- CMainWindow::CMainWindow()
- {int Row;
- CString s = "FCE Test";
- LoadAccelTable( "MainAccelTable" );
- Create( NULL, "MFC Example Program",
- WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" );
- for(Row=0;Row<NROWS;Row++) Buffer[Row].Empty;
- TheRow = 0;
- }
-
- // Display character on screen
-
- void CMainWindow::DisplayChar(int nChar)
- {int Row;
- // process the character
- if(nChar==10) return;
- if(nChar==13)
- {if(TheRow<NROWS-1) TheRow++;
- else
- {// scroll page (TheRow==NROWS-1)
- for(Row=0;Row<=NROWS-2;Row++) Buffer[Row] = Buffer[Row+1];
- Buffer[NROWS-1].Empty();
- TheRow = NROWS-1;
- }
- }
- else
- {// stuff character into display buffer
- Buffer[TheRow] += (char)nChar;
- }
- }
-
- // Display string on screen
-
- void CMainWindow::DisplayString(CString Text)
- {
- Buffer[TheRow] += Text;
- Invalidate(TRUE);
- MainWndPtr->UpdateWindow();
- }
-
- // Display line on screen
-
- void CMainWindow::DisplayLine(CString Text)
- {
- Buffer[TheRow] += Text;
- DisplayChar(13);
- Invalidate(TRUE);
- MainWndPtr->UpdateWindow();
- }
-
- // CMainWindow message map
-
- BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
- //{{AFX_MSG_MAP( CMainWindow )
- ON_WM_PAINT()
- ON_COMMAND(ID_EXIT, PgmExit)
- ON_COMMAND(ID_LOGON, PgmLogon)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- CTheApp NEAR theApp;
-
- // PgmExit: Exits application
-
- void CMainWindow::PgmExit(void)
- {
- PostQuitMessage(0);
- }
-
- // display error message
-
- void CMainWindow::ShowError(int Code)
- {static char Buffer[65];
- static char Temp[90];
- fceErrorText(0,Code,(LPSTR)Buffer,65);
- wsprintf((LPSTR)Temp,"FCE Error %d: %s\n", Code, (LPSTR)Buffer);
- DisplayLine((LPSTR)Temp);
- }
-
- // PgmLogon : Log onto FTP site
- void CMainWindow::PgmLogon(void)
- {int Code;
- ULONG ByteCount;
- char Temp[90];
- CMenu *pMenu;
-
- #if 1
- #define SRVR_NAME "ftp.marshallsoft.com"
- #define USER_NAME "anonymous"
- #define PASSWORD "you@yourisp.com"
- #define DIRECTORY "msc/other"
- #define FILE_NAME "products.txt"
- #else
- #define SRVR_NAME "10.0.0.1"
- #define USER_NAME "mike"
- #define PASSWORD "mike"
- #define FILE_NAME "products.txt"
- #endif
-
- // disable LogOn menu item
- pMenu = MainWndPtr->GetMenu();
- pMenu->EnableMenuItem(ID_LOGON, MF_BYCOMMAND|MF_GRAYED);
- // attach FCE
- fceAttach(1);
- // define LOG file
- Code = fceSetString(0,FCE_SET_LOG_FILE,(LPSTR)"mfc_pgm.log");
- // connect to FTP server
- DisplayString("Connecting to server ");
- DisplayLine(SRVR_NAME);
- Code = fceConnect(0,(LPSTR)SRVR_NAME,(LPSTR)USER_NAME,(LPSTR)PASSWORD);
- if(Code<0)
- {ShowError(Code);
- return;
- }
- DisplayLine("OK");
- #ifdef DIRECTORY
- // change to proper directory
- Code = fceSetServerDir(0, (LPSTR)DIRECTORY);
- if(Code<0)
- {ShowError(Code);
- return;
- }
- #endif
- // set to ASCII xfer mode
- fceSetMode(0,'A');
- // download the file
- DisplayString("Please wait while file ");
- DisplayString(FILE_NAME);
- DisplayLine(" is being downloaded...");
- Code = fceGetFile(0,(LPSTR)FILE_NAME);
- if(Code<0)
- {ShowError(Code);
- return;
- }
- // display final count
- ByteCount = fceGetInteger(0, FCE_GET_FILE_BYTES_RCVD);
- wsprintf((LPSTR)Temp,"Download complete. %d bytes received.\n",ByteCount);
- DisplayLine((LPSTR)Temp);
- // QUIT
- fceClose(0);
- fceRelease();
- Invalidate(TRUE);
- }
-
- // OnPaint:
-
- void CMainWindow::OnPaint()
- {int Row;
- CPaintDC dc( this );
- CRect rect;
- GetClientRect( rect );
- dc.SetTextAlign( TA_BASELINE | TA_LEFT );
- dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) );
- dc.SetBkMode(TRANSPARENT);
- dc.SelectStockObject(ANSI_FIXED_FONT);
- for(Row=0;Row<=TheRow;Row++)
- {// display the row
- dc.TextOut( 4, 16+(Row<<4), Buffer[Row], Buffer[Row].GetLength() );
- }
- }
-
- // InitInstance:
-
- BOOL CTheApp::InitInstance()
- {SetDialogBkColor(); //hook gray dialogs
- m_pMainWnd = new CMainWindow();
- m_pMainWnd->ShowWindow( m_nCmdShow );
- m_pMainWnd->UpdateWindow();
- MainWndPtr = m_pMainWnd;
- return TRUE;
- }